import time

from Auto.day02.login.Login_Operation import Login_Operation
from selenium.webdriver.common.by import By
import pytest

class Card_Operation(Login_Operation):

    #添加银行卡
    @pytest.fixture(scope='function')
    def new_card(self,login_driver,bank,kind,card_number):
        self.logins(login_driver)
        login_driver.get('http://localhost:90/user/personal/toBankCard.html')
        # 新增按钮
        login_driver.find_element(By.XPATH, '//*[@id="bankCard_add_modal_btn"]').click()
        time.sleep(1)
        #银行
        login_driver.find_element(By.XPATH,'//*[@id="cardBank_add_input"]').send_keys(bank)

        #种类
        if kind == '信用卡':
            login_driver.find_element(By.XPATH,
                                      '//*[@id="bankCardAddModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[2]/span').click()
        elif kind == '借记卡':
            login_driver.find_element(By.XPATH,
                                      '//*[@id="bankCardAddModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[1]/span').click()
        #卡号
        login_driver.find_element(By.NAME, 'cardnum').send_keys(card_number)
        time.sleep(1)
        #确认
        login_driver.find_element(By.XPATH, '//*[@id="bankCard_save_btn"]').click()
        time.sleep(0.5)
    #删除银行卡
    @pytest.fixture(scope='function')
    def del_card(self,login_driver,card_number,login_page):
        # self.logins(login_driver)
        login_driver.get('http://localhost:90/user/personal/toBankCard.html')
        time.sleep(1)
        # 选择卡号
        login_driver.find_element(By.CSS_SELECTOR,f'button.delete_btn[delete-name="{card_number}"]').click()
        # login_driver.find_element(By.CSS_SELECTOR, f'button.delete_btn[delete-name="{creditnum}"]').click()
        time.sleep(1)
        #确认删除
        login_driver.find_element(By.XPATH,
                                  '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(0.5)
    #修改银行卡
    @pytest.fixture(scope='function')
    def update_card(self,login_driver,username,password,card_ID,bank,kind,card_number,login_page):
        login_driver.get('http://localhost:90/user/personal/toBankCard.html')
        time.sleep(1)
        # 选择卡号
        login_driver.find_element(By.CSS_SELECTOR,f'button.update_btn[update-id="{card_ID}"]').click()
        time.sleep(1)
        # 银行
        login_driver.find_element(By.XPATH,'//*[@id="cardBank_update_input"]').clear()

        login_driver.find_element(By.XPATH,'//*[@id="cardBank_update_input"]').send_keys(bank)
        # 种类  //*[@id="bankCardUpdateModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[1]/span
        if kind == '信用卡':
            login_driver.find_element(By.XPATH,
                                      '//*[@id="bankCardUpdateModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[2]/span').click()
        elif kind == '借记卡':
            login_driver.find_element(By.XPATH,
                                      '//*[@id="bankCardUpdateModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[1]/span').click()
        # 卡号
        login_driver.find_element(By.XPATH,'//*[@id="cardNum_update_input"]').clear()
        login_driver.find_element(By.XPATH,'//*[@id="cardNum_update_input"]').send_keys(card_number)
        # 确认
        login_driver.find_element(By.XPATH,'//*[@id="bankCard_update_btn"]').click()
        time.sleep(0.5)


    def getSuccessMsg(self,login_driver):
        #删除：/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div

        #新增：/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div

        #修改：/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div
        #//div[@class='jconfirm-content']/div
        #/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div
        text = login_driver.find_element(By.XPATH,"//div[@class='jconfirm-content']/div").text
        time.sleep(1)
        return text
